<?php
/**
 * Created by PhpStorm.
 * User: 69548
 * Date: 2018/8/17
 * Time: 15:13
 */

namespace app\wap\controller;


use think\Controller;

class Basewap extends Controller
{
    public $member_pcode='';
    public function _initialize()
    {
        header('Access-Control-Allow-Origin:*');

        $uid = request()->request('uid');
        $member_id = request()->request('member_id');
        //分享分销判断
        if  (!empty($uid)){
            $this->member_pcode=  $uid;
            $uids=db('member')->where('member_id',$uid)->find();
            if (!empty($member_id) && $uid != $member_id && $uids['member_pcode'] != $member_id ){
                db('member')->where('member_id',$member_id)->update([
                    'member_pcode'=> $uid
                ]);
            }
        }
        if (request()->isPost()){
            $token=input('token');
            $member_id=input('member_id');
            if (empty($token)){
                echo json_encode(['msg'=>'参数错误','code'=>'101']);die();//100等于token不存在
            }
            if($token != 'fasle88888888' && $member_id != 'fasle88888888'){
                $tokens=db('member')->where('member_id',$member_id)->find();
                if (empty($tokens['token'])){
                    echo json_encode(['msg'=>'参数错误','code'=>'102']);die();//100等于token不存在
                }else{
                    if ($tokens['token']!=$token){
                        echo json_encode(['msg'=>'参数错误','code'=>'103']);die();//103等于token不相等
                    }
                }
            }
        }else{
            echo json_encode(['msg'=>'非法请求','code'=>'100']);die();//100等于token不存在
        }
    }


}